package com.hua.designpattern.structural.flyweight;

import java.util.HashMap;
import java.util.Map;

public class ColorFlyWeight {
	private static Map<String, Color> colorFactory = new HashMap<String, Color>();

	public static synchronized Color getColor(String name) {
		name = name.toUpperCase();
		Color color = colorFactory.get(name);
		if (color != null) {
			System.out.println("---reuse Color: " + color);
		} else {
			color = new Color(name);
			colorFactory.put(name, color);
			System.out.println("create new Color: " + color);
		}
		return color;
	}
}
